package com.suse.service.vod.service.impl;

import com.suse.common.config.response.ApiException;
import com.suse.common.config.response.R;
import com.suse.common.util.core.StringUtil;
import com.suse.service.vod.service.VideoService;
import com.suse.service.vod.util.VodUtil;
import org.springframework.stereotype.Service;
import org.springframework.web.multipart.MultipartFile;

@Service
public class VideoServiceImpl implements VideoService {

    @Override
    public R uploadVideo(MultipartFile file) {
        String videoId = VodUtil.upload(file);
        if (StringUtil.isEmpty(videoId)) {
            throw new ApiException("上传失败！");
        }
        return R.put("videoId",videoId).success("上传成功");
    }

    @Override
    public R playVideo(String vid) {
        String playAuth = VodUtil.getPlayAuth(vid);
        if (StringUtil.isEmpty(playAuth)) {
            throw new ApiException("获取视频播放凭证失败");
        }
        return R.put("playAuth",playAuth).success();
    }

}
